from typing import List


class Solution:
    def asteroidCollision(self, asteroids: List[int]) -> List[int]:
        stack = []
        i = 0
        while True:
            if i >= len(asteroids):
                break
            if len(stack) == 0:
                stack.append(asteroids[i])
                i += 1
            elif stack[-1] > 0 > asteroids[i]:
                a, b = abs(stack[-1]), abs(asteroids[i])
                if a == b:
                    stack.pop()
                    i += 1
                elif a < b:
                    stack.pop()
                elif a > b:
                    i += 1
            else:
                stack.append(asteroids[i])
                i += 1
        return stack

